home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C# & Game Programming - A…er's Guide (2nd Edition)
/
Buono 2nd Ed.iso
/
Chapter5
/
5.33
/
5.33.cs
next >
Wrap
Text File
|
2004-10-30
|
1KB
|
40 lines
/* Public Inheritance with protected members. */
using System;
namespace Chapter5 {
public class BaseClass {
protected short Width, Length;
public BaseClass() {}
public BaseClass(short w, short l) {
Width = w;
Length = l;
}
public static void ReadWidth(BaseClass X) {
Console.WriteLine(X.Width);
}
public static void ReadLength(BaseClass X) {
Console.WriteLine(X.Length);
}
}
public class DerivedClass : BaseClass {
DerivedClass(short w, short l) {
Width = w;
Length = l;
}
public static void DisplayArea(DerivedClass Y) {
Console.WriteLine("Area = " + Y.Width * Y.Length);
}
static void Main() {
DerivedClass Instance = new DerivedClass(5, 6);
ReadWidth(Instance);
ReadLength(Instance);
DisplayArea(Instance);
}
}
}